package com.donfu.web.controller.wxhouse;

import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.core.page.TableDataInfo;
import com.donfu.system.domain.dto.HouseSpecParamDTO;
import com.donfu.system.domain.house.HouseGoods;
import com.donfu.system.service.house.IHouseGoodsService;
import com.donfu.system.service.house.IHouseSpecParamService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前台--商品详情页
 *
 * @author donfu
 * @date 2021-12-08
 */
@Api(tags = "前台--商品详情页")
@RestController
@RequestMapping("wx/house/goodsDetails")
public class WebGoodsDetailsController extends BaseController {

    @Autowired
    private IHouseGoodsService houseGoodsService;

    @Autowired
    private IHouseSpecParamService houseSpecParamService;

    /**
     * 查询商品详情页面信息
     */
    @ApiOperation("查询商品详情页面信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品信息ID", dataType = "Long", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", required = true)
    })
    @GetMapping("/pageDetails")
    public AjaxResult pageDetails(@RequestParam("goodsId") Long goodsId,
                                  @RequestParam("userId") Long userId)
    {
        return AjaxResult.success(houseGoodsService.getHouseGoodsByIdAndUserId(goodsId, userId));
    }

    /**
     * 查询商品下的规格参数
     */
    @ApiOperation("查询商品下的规格参数(已废除)")
    @ApiImplicitParam(name = "goodsId", value = "商品信息ID", dataType = "Long", required = true)
    @GetMapping("/getSpecParams")
    public AjaxResult getSpecParams(@RequestParam("goodsId") Long goodsId)
    {
        List<HouseSpecParamDTO> specParams = houseSpecParamService.getSpecParamTree(goodsId);
        return AjaxResult.success(specParams);
    }

    /**
     * 根据商品ID集合查询商品
     */
    @ApiOperation("根据商品Id集合查询商品")
    @ApiImplicitParam(name = "ids", value = "商品信息ID集合", dataType = "Long", required = true)
    @GetMapping("/{ids}")
    public AjaxResult getHouseGoodsByIds(@PathVariable("ids") Long[] ids){

        return AjaxResult.success(houseGoodsService.getHouseGoodsByIds(ids));
    }

}
